<template>
  <div class="page-container">
    <div class="box-wrapper" v-if="thirdServiceDetail.jianlianEnabled !== ''">
      <div class="logo-title-wrapper">
        <span class="title">聚合支付服务</span>
        <span class="open" v-if="thirdServiceDetail.jianlianEnabled">已开通</span>
        <span class="close" v-else>暂未开通</span>
      </div>
      <div class="text">
        {{ thirdServiceDetail.jianlianEnabled ? '如需关闭聚合支付服务请联系启程的工作人员' : '如需开通聚合支付服务请联系启程的工作人员' }}
      </div>
      <div class="more-bills" v-if="thirdServiceDetail.payedCount > 0" @click="goTo"> 查看更多账单<icon-right /> </div>
      <!-- 已开通-->
      <div class="payee-box" v-if="thirdServiceDetail.jianlianEnabled">
        <div class="payee">
          <p>收款笔数</p>
          <p class="payee-value">{{ thirdServiceDetail.payedCount || 0 }} 笔</p>
        </div>
        <a-divider class="divider" direction="vertical" />
        <div class="payee">
          <p>收款总额</p>
          <p class="payee-value">{{ thirdServiceDetail.payedTotalAmount || 0 }} 元</p>
        </div>
      </div>
      <!-- 未开通-->
      <template v-else>
        <div class="money" v-for="(item, index) in serviceList" :key="index">
          <img :src="item.icon" width="54" height="54" />
          <div class="msg">
            <div class="money-title">{{ item.title }}</div>
            <div class="money-text">{{ item.desc }}</div>
          </div>
        </div>
      </template>
    </div>
  </div>
</template>

<script setup>
  import { ref, reactive } from 'vue'
  import { useRouter } from 'vue-router'
  import { usePermission } from '@/hooks/usePermission'
  import { Message } from '@arco-design/web-vue'
  import { thirdServiceStatistics } from '@/api/finance/thirdPayment'
  const router = useRouter()
  const serviceList = ref([
    {
      title: '支持多渠道支付',
      desc: '支持消费者使用支付宝、微信、云闪付扫码付款',
      icon: new URL(`@/assets/polymerisation_1.png`, import.meta.url).href,
    },
    {
      title: '实时获取支付结果',
      desc: '消费者扫码完成支付后，费用的状态根据消费者的支付结果实时返回',
      icon: new URL(`@/assets/polymerisation_2.png`, import.meta.url).href,
    },
    {
      title: '费用与流水关联绑定',
      desc: '依靠支付结果的真实性，确保费用与流水的深度绑定',
      icon: new URL(`@/assets/polymerisation_3.png`, import.meta.url).href,
    },
  ])
  // 三方支付详情
  const initThirdService = {
    payedCount: '', // 支付笔数
    payedTotalAmount: '', // 支付总金额
    jianlianEnabled: '', // 服务状态
    jianlianEnabledName: '', // 服务状态名称
  }
  // 服务状态
  const thirdServiceDetail = reactive(initThirdService)
  const getDetailApi = () => {
    thirdServiceStatistics().then(({ result }) => {
      Object.assign(thirdServiceDetail, result)
    })
  }

  const goTo = () => {
    // 跳转三方支付账单
    usePermission('svms:finance:tripartitePayment')
      ? router.push({ path: '/finance/tripartitePayment' })
      : Message.warning(`无法跳转，暂无三方支付账单的页面权限 `)
  }

  getDetailApi()
</script>

<style lang="less" scoped>
  .page-container {
    .more-bills {
      color: #1890ff;
      cursor: pointer;
      font-weight: 500;
      font-size: 16px;
    }
    .payee-box {
      margin-top: 56px;
      display: flex;
    }
    .payee {
      font-weight: 400;
      font-size: 16px;
      color: #4e5969;
    }
    .payee-value {
      font-weight: 600;
      font-size: 18px;
      color: #1890ff;
      margin-top: 4px;
    }
    .divider {
      margin: 0 40px;
    }
    .box-wrapper {
      display: flex;
      justify-content: flex-start;
      flex-direction: column;
      align-items: flex-start;
      width: 100%;
      height: 80vh;
      padding: 74px 0 0 57px;
      background-image: url('../../../assets/box-bg.png') !important;
      background-size: cover;

      .logo-title-wrapper {
        position: relative;
        .title {
          font-weight: 500;
          font-size: 32px;
          color: #1d2129;
          line-height: 40px;
        }
        .open,
        .close {
          vertical-align: top;
          padding: 0px 10px;
          font-weight: 600;
          font-size: 12px;
          color: #ffffff;
          background: linear-gradient(222deg, #ff7a66 0%, #ff5b60 100%);
          border-radius: 60px;
        }
        .close {
          color: #919aa5;
          background: linear-gradient(222deg, #f2f3f5 0%, #dbdbdb 100%);
        }
      }
      .text {
        font-weight: 400;
        font-size: 14px;
        color: #919aa5;
        margin: 12px 0 20px 0;
      }
      .money {
        display: flex;
        align-items: center;
        margin-top: 20px;
        .money-title {
          font-weight: 500;
          font-size: 16px;
          color: #1d2129;
          margin-bottom: 3px;
        }
        .money-text {
          font-weight: 400;
          font-size: 12px;
          color: #919aa5;
        }
      }
    }
  }
</style>
